package com.yc.study.service.impl;

import com.yc.study.mapper.AnalyzeMapper;
import com.yc.study.service.AnalyzeService;
import com.yc.study.util.DateUtils;
import com.yc.study.vo.UserRegistrationAnalysisVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static com.yc.study.util.DateUtils.FORMAT_yyyyMMdd;

/**
 * @author 75073
 */
@Service
public class AnalyzeServiceImpl implements AnalyzeService {

  @Autowired private AnalyzeMapper analyzeMapper;

  @Override
  public List<UserRegistrationAnalysisVo> loadList() {
    ArrayList<UserRegistrationAnalysisVo> analysisVos = new ArrayList<>();
    // 生成最近七天的日期
    List<Date> dates = DateUtils.generateDates(new Date(), 7);
    dates.forEach(
        date -> {
          Date addDay = org.apache.commons.lang3.time.DateUtils.addDays(date, 1);
          UserRegistrationAnalysisVo userRegistrationAnalysisVo = analyzeMapper.selectCount(addDay);
          userRegistrationAnalysisVo.setDateStr(FORMAT_yyyyMMdd.format(date));
          analysisVos.add(userRegistrationAnalysisVo);
        });
    return analysisVos;
  }
}
